<?php

/**
 * @deprecated Pouzi triedu Db_DbTable_*
 * 
 * Professor
 *  
 * @author rdy
 * @version 
 */

require_once 'Zend/Db/Table/Abstract.php';

class Db_Professor extends Zend_Db_Table_Abstract {
	
	/**
	 * The default table name 
	 */
	protected $_name = 'professor';
	
	/**
	 * Primary key
	 */
	protected $_primary = 'pid';
	
	/**
	 * Zavisle tabulky
	 */
	protected $_dependentTables = array('Db_ProfessorCommission');
	
	/**
	 * 
	 * @param array $data
	 */
	public function insert(array $data){				

		if(isset($data[0])){
			$info = $this->info('cols');
			$dataKeys = array_keys($data[0]);
			$infoValues = array_values($info);
			$diff = array_diff($infoValues,$dataKeys);		
		
			if($diff[0] == $this->_primary[1]){
				$adapter = $this->getAdapter();
				$adapter->beginTransaction();
				try{
					for($i = 0; $i < count($data); $i++){
						$adapter->query('INSERT INTO professor(title_before,firstname,lastname,title_behind)
										 VALUES(?,?,?,?)',array(
											$data[$i]['title_before'],
											$data[$i]['firstname'],
											$data[$i]['lastname'],
											$data[$i]['title_behind']
										)
						);
					}
					
					$adapter->commit();	
					
					Zend_Debug::dump($this->_primary,'Primary');
						
				} catch (Zend_Db_Exception $e){
					/*
					 * TODO dorobit logivanie
					 */
					$adapter->rollBack();
					throw new Db_Exception($e->getMessage());
				}
			}
		}
		else {
			parent::insert($data);
		}		
	}
}